<template>
    <SchemaForm v-model="searchType" :columns="columns" @searchHandle="search" @handleReset="handleReset" />
</template>

<script lang="ts" setup>
import SchemaForm from '@/components/SchemaForm.vue'

export type SearchType = Record<'no' | 'stockChangeType' | 'date', string>

const typeList = reactive([
    {
        value: '',
        label: '全部',
    },
    {
        value: 'ALLOCATION_INBOUND',
        label: '调拨入库',
    },
    {
        value: 'OTHER_INBOUND',
        label: '其它入库',
    },
    {
        value: 'ALLOCATION_OUTBOUND',
        label: '调拨出库',
    },
    {
        value: 'OTHER_OUTBOUND',
        label: '其它出库',
    },
])
const searchType = reactive({
    no: '',
    stockChangeType: '',
    date: '',
})
const columns = [
    {
        label: '订单号',
        prop: 'no',
        valueType: 'copy',
        fieldProps: {
            placeholder: '请输入订单号',
        },
    },
    {
        label: '类型',
        labelWidth: '40px',
        prop: 'stockChangeType',
        valueType: 'select',
        options: typeList,
        fieldProps: {
            placeholder: '请选择类型',
        },
    },
    {
        label: '出入库时间',
        prop: 'date',
        valueType: 'date-picker',
        labelWidth: '85px',
        fieldProps: {
            type: 'datetimerange',
            startPlaceholder: '开始日期',
            endPlaceholder: '结束日期',
            format: 'YYYY/MM/DD HH:mm:ss',
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
        },
    },
]
const $emit = defineEmits(['onSearchParams'])

function search() {
    $emit('onSearchParams', toRaw(searchType))
}
const handleReset = () => {
    ;(Object.keys(searchType) as (keyof SearchType)[]).forEach((key) => (searchType[key] = ''))
    search()
}
</script>
